package com.qzsoft.zhjd.materiel.modules.materielconsume.controller;

import java.util.Map;


import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.jeemis.common.validator.ValidatorUtils;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.materiel.modules.materielconsume.dto.MaterielConsumeListDto;
import com.qzsoft.zhjd.materiel.modules.materielconsume.entity.MaterielConsumeEntity;
import com.qzsoft.zhjd.materiel.modules.materielconsume.service.MaterielConsumeService;

/**
 * @ClassName MaterielConsumeController
 * @Description 材料消耗控制器
 * @author linhuawei
 * @since 2022-04-05
 */
@RestController
@RequestMapping("/api/materielConsume")
public class MaterielConsumeController {

    @Autowired
    private MaterielConsumeService materielConsumeService;

    /**
     * @Title page
     * @Description 获取材料消耗分页数据
     * @param params 查询条件
     * @return 材料消耗分页数据
     */
    @RequiresPermissions("materiel:consume:page")
    @GetMapping("/page")
    public Result<IPage<MaterielConsumeListDto>> page(@RequestParam Map<String, Object> params) {
        IPage<MaterielConsumeListDto> page = materielConsumeService.pageDto(params);
        return ResultUtils.ok(page);
    }

    /**
     * @Title save
     * @Description 添加数据
     * @param entity 需要添加的数据
     * @return 添加结果
     */
    @RequiresPermissions("materiel:consume:save")
    @PostMapping("/save")
    public Result<String> save(@RequestBody MaterielConsumeEntity entity) {
        ValidatorUtils.validateEntity(entity);
        materielConsumeService.save(entity);
        return ResultUtils.ok();
    }

}
